#pragma once
#include "../../../../include/singleton.h"
#include "../../../../include/net_interface.hpp"
#include "../../../../include/objpool.hpp"

#include "client.h"

class CSvrPacketParser :
    public IPacketParser
{
public:
    virtual INT32 ParsePacket(const char* pData, const INT32 iLen);
};

class CNetMgr :
    public ISessionManager
{
    DECLARE_SINGLETON(CNetMgr)
public:
    CNetMgr(void);
    virtual ~CNetMgr(void);

    bool Init(void);
    void UnInit(void);
    bool Run(void);

    virtual void OnEstablish(HNETHANDLE hHandle, HSESSION hSession);
    virtual void OnTerminate(HSESSION hSession);
    virtual void OnError(HNETHANDLE hHandle, HSESSION hSession, INT32 iModuleError, INT32 iSystemError);
    virtual void OnRecv(HSESSION hSession, const char* pData, const INT32 iLen);

    inline INetManager* get_net_mgr(void){return m_net_mgr;}

    inline CObjPool<CConeTestSession>& get_cone_test_session_pool(void){return m_pool_cone_test_session;}
protected:
    INetManager*        m_net_mgr;
    HNETHANDLE          m_listen_client;
    HNETHANDLE          m_listen_nat_test;
    CSvrPacketParser    m_pkg_parser;
    CObjPool<CClient>   m_pool_client;
    CObjPool<CNATTestSession> m_pool_nat_test_session;
    CObjPool<CConeTestSession> m_pool_cone_test_session;
};
